import warnings
import tensorflow as tf
from typing import TYPE_CHECKING,Union
from tensorflow.keras.utils import CustomObjectScope

from nlp_tools import  custom_objects
from nlp_tools.utils.serialize import load_data_object
from nlp_tools.utils.data import get_list_subset
from nlp_tools.utils.data import unison_shuffled_copies
from nlp_tools.utils.multi_label import MultiLabelBinarizer
import random
import os
import numpy as np
import yaml

from keras.api._v2.keras.utils import set_random_seed

def custom_object_scope() -> CustomObjectScope:
    return tf.keras.utils.custom_object_scope(custom_objects)


def seed_tensorflow(seed=42):
    set_random_seed(seed)
    os.environ['PYTHONHASHSEED'] = str(seed)
    os.environ['TF_DETERMINISTIC_OPS'] = '1' # pip install tensorflow-determinism


def yaml_loader(file_name):
    '''
    加载yaml文件，返回一个json对象
    :param file_name:
    :return:
    '''
    with open(file_name, encoding='utf-8') as fread:
        config = yaml.safe_load(fread)
    return config

